package main

import (
	"fmt"
	ziface "zinx/Ziface"
	znet "zinx/Znet"
)

// ping test 自定义路由
type PingRouter struct {
	znet.BaseRouter
}

// 重写路由方法
func (this *PingRouter) PreHandler(request ziface.IRuquest) {

	fmt.Println("Call Router PreHandler")
	_, err := request.GetConnection().GetTCPConnection().Write([]byte("before ping...\n"))
	if err != nil {
		fmt.Println("call back before err")
	}
}

func (this *PingRouter) Handler(request ziface.IRuquest) {

	fmt.Println("Call Router PreHandler")
	_, err := request.GetConnection().GetTCPConnection().Write([]byte("ping....ping....ping\n"))
	if err != nil {
		fmt.Println("call back before err")
	}
}

func (this *PingRouter) PosteHandler(request ziface.IRuquest) {
	fmt.Println("Call Router PreHandler")
	_, err := request.GetConnection().GetTCPConnection().Write([]byte("after ping...\n"))
	if err != nil {
		fmt.Println("call back before err")
	}
}

func main() {

	//1.创建一个server句柄
	s := znet.NewServer("[zinxv0.3]")
	s.AddRouter(&PingRouter{})
	s.Serve()
	//启动Server
}
